#include<bits/stdc++.h>
using namespace std;
signed main() {
    int n;
    scanf("%d", &n);

    while(n--) {
        vector<int> t(1005);
        vector<bool> chk(1005);

        int cnt, sum;
        cnt = sum = 0;

        while(1) {

            int num, hh, mm;
            char ch;

            scanf("%d %c %d:%d", &num, &ch, &hh, &mm);

            if(!num)	break;

            if(ch == 'E') {
                if(!chk[num])	continue;

                sum += hh * 60 + mm - t[num];
                chk[num] = 0;
                cnt++;
            } else {
                t[num] = hh * 60 + mm;
                chk[num] = 1;
            }
        }
        if(!cnt)
            printf("0 0\n");
        else {
            printf("%d %d\n", cnt, (int)(1.0 * sum / cnt + 0.5));
        }
    }
    return 0;
}

